import model.ActionType;
import model.Game;
import model.Hockeyist;
import model.HockeyistState;
import model.Move;
import model.World;

/**
 * Created by Constantine on 23.09.2014.
 */
public class Pickup extends HelpObject implements AbstractStrategy {

    public Pickup(Hockeyist self, World world, Game game, Move move) {
        super(self, world, game, move);
    }

    @Override
    public void run() {
        if (self.getState() == HockeyistState.SWINGING) {
            move.setAction(ActionType.STRIKE);
            return;
        }
        move.setAction(ActionType.TAKE_PUCK);
        long nearestToPuckId = getNearestTo(puck, getUnits(puck));

        if (getHockeyistById(nearestToPuckId).isTeammate()) { // если тиммейт ближе всех к шайбе
            if (nearestToPuckId == self.getId()) {    // если это я
                Moving.to(puck);
            } else {  // если не я, то бегу дефить
                Moving.moveByDefendLine(getNet(false));
            }
        } else {
            if (getTeammates(getDefenedPoint()).get(0).getId() == self.getId()) { // если я ближе к точке защиты
                Moving.moveByDefendLine(getNet(false));
            } else {
                if (BACK_AFTER_SHOOT > 0 && selfX < 0) {
                    move.setSpeedUp(1.0d);
                    move.setTurn(self.getAngleTo(getNet(false)));
                } else if (puckX < Vars.PICKUP_X_MOVE_PUCK) {
                    Moving.to(Point.getPoint(0.4d, 0.0d), puck);
                } else {
                    Moving.to(puck);
                }
            }
        }
        if (selfX < 0 && Moving.atStickSector(self, puck) && Moving.getSpeed(puck) > 10) {
            move.setAction(ActionType.STRIKE);
        }
        if (oppBlock(self, true)) {
            move.setAction(ActionType.STRIKE);
        }
    }

}
